/*
*  FileSelect 移动文件指令
*/

var knowledgebase = angular.module("knowledgebase", ['angularFileUpload', 'vModal', 'ngAnimate', 'Common', 'dropdownApp', 'cgBusy', 'tm.pagination', 'FileSelect', 'filepreview', 'PensonSelector', 'personnelmanagementS', 'knowledgebaseS', 'loadModule', 'nstdirective','wangeditordrective'])
// 属性框
 .factory('fileAttribute', function (vModal) {
     return vModal({
         controller: 'addAttributecontroller',
         controllerAs: 'fileAttribute',
         templateUrl: '/system/views/train/fileattribute.html'
     });
 })
// 设置焦点 标签用
 .directive('setFocus', function () {
     return function (scope, element) {
         element[0].focus();
     };
 })
.directive('resize', function ($window) {
    return function (scope, element) {
   
    }
})

.controller("upfile", ["$scope", "$document", "FileUploader", "MsgCon", "sysUserInfo", "RequestTrainService", "fileAttribute", 'Msg',"$timeout", '$rootScope','$window', function ($scope, $document, FileUploader, MsgCon, sysUserInfo, RS, fileAttribute, Msg,$timeout,$rootScope,$window) {
    $rootScope.btnTab = "index.know.knowledgebase";
    $scope.mytextwd = "";
    $scope.myfujianwd = []; //获得到附件列表    
    // 判断数字
    $scope.numtoInfinite = function(num,Company){
        if(num == -1 || num == 0 || num == undefined || num == null || num == "" || num =="0 KB"){
            return "未限制";
        }else{
            if(Company == undefined || Company == null || Company == ""){
                return num;
            }else{
                return num+Company;
            }                        
        }
    } 
    $scope.pathisdata={
        name:"",
        path:"",
        isShow:false
    };
    //  打开获取文件地址
    $scope.openPath = function(item){                
        $scope.pathisdata.name =item.fileName;
        $scope.pathisdata.path = item.fileurlonly;
        $scope.pathisdata.isShow = true;
    } 
    $scope.isImg = function(pathImg){ 
        var ImgObj=new Image();  
        ImgObj.src= pathImg;  
         if(ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0))  
         {  
           return true;  
         } else {  
           return false;  
        }  
    }  
     // 全局上传控件
    $scope.allPlayUpload = function(){
        if($scope.discon.disupfile){
            return;
        }
        $scope.UploadParams = { //上传必要的参数
          obj:this, // angular 对象
          apply:$scope.$apply,  //文件刷新
          userobj:sysUserInfo.getuserinfo(),
          list:$scope.kblist.lenght <= 0?[]:$scope.kblist,   //文件列表   
          fobj:$scope.dbkbids.length==1 ?$scope.dbkbids[0]: null,// 父级对象   
          optype:1, // 文件上传类型     
          msg:Msg          
        };
        //调用文件上传的 主接口 在主框架中
        allSelectFileObj($scope.UploadParams);
    }
    $rootScope.btnTab = "index.know.knowledgebase";   //用于判断按扭权限使用
    $scope.btnlist = { savefun: false, addinfo: false, editinfo: false, delinfo: false,exportinfo:false };
    $scope.discon={"disnewfile":false,"disupfile":false};//新建文件夹、上传文件、


    //这里是导出
        $scope.ExportList=function(){
             $scope.loading = true;
             RS.prescriptionImport({uid:sysUserInfo.getuserinfo().user_ID,type:30}).then(function(data){                          
                    $scope.loading = false;
                    if (data.errorcode == "0") {
                        window.location = data.errormsg;
                    }else if (data.errorcode == "73") {
                        setTimeout(function () {
                            $scope.ExportList();
                        }, 5000);
                        Msg.warning("正在统计请稍后..");
                    } else {
                        Msg.error("导出失败 ！");
                    }
                }, function callback() {                     
                    $scope.loading = false;           
                });    
        }


    /*****************************************控制文件指令的************************************************/
    $scope.isupobj = { "upflag": false, "isbtn": false, "datas": [] };   // 初始化    
    $scope.isupflagfun = function () {//点击查看传输列表
        $scope.isupobj.isbtn = true; // 标志按扭点击的
        $scope.isupobj.upflag = !$scope.isupobj.upflag;
        if ($scope.isupobj.upflag) {    // 向服务器拿数据 放这边会重置datas所以放初始化       
            //            then(function (data) {
            //                $scope.isupobj.datas = data;
            //            }, function callback() { });
        }
    }    
      /*************************************************记事本******************************************************/
    $scope.notepadConfig = {
        //这里可以选择自己需要的工具按钮名称,此处仅选择如下五个  'insertimage', 'horizontal','spechars','attachment', 'simpleupload',
        toolbars: [
       [ 'undo', 'bold', 'italic',
              'underline',  'strikethrough',  'removeformat', 'formatmatch', '|', 'forecolor', 'insertorderedlist', 'insertunorderedlist', '|',
            'paragraph', 'indent', '|',
            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|','link',
             'date', 'time',  '|',
            'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols']

     ],


        //关闭字数统计
        wordCount: false,
        //关闭elementPath
        elementPathEnabled: false,
        enableAutoSave: false, //不自动保存
       // initialContent:'请在此输入文本...'
    };    
    /*******************************************问答*******************************************/
    $scope.questionConfig = {
        //这里可以选择自己需要的工具按钮名称,此处仅选择如下五个 'insertimage', 'insertvideo', 'simpleupload',
        toolbars: [
       ['source', '|', 'undo', 'redo', '|',
            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', '|','insertorderedlist', 'insertunorderedlist',
            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|',
             'insertcode', '|','removeformat']
     ],
        //关闭字数统计
        wordCount: false,
        //关闭elementPath
        elementPathEnabled: false,
        enableAutoSave: false, //不自动保存
        //initialContent:'请在此输入你想要提出的问题...'
    };   


    /*********************************************文件上传开始**********************************************/
    $scope.List = [];
    $scope.upcenghide = function () {
        $scope.upcengflag = true;
        // 由于这个class 可能 不是angularjs 生成的 所以只能通过dom操作删除
        if (document.getElementById('hidecengnew') != undefined) {
            document.getElementById('hidecengnew').setAttribute("class", "knowledgeliebiao_miankongbai");
        }
    }
    //上传scrom
    $scope.selectScromFile=function(){
        document.getElementById("scromFileUpload").click();
    }
    var trainupfile = $scope.isupobj.datas = $scope.uploader = new FileUploader();
    trainupfile.onWhenAddingFileFailed = function (item /*{File|FileLikeObject}*/, filter, options) {     // 选择文件后失败       0
        console.info('onWhenAddingFileFailed', item, filter, options);
    };
    trainupfile.onAfterAddingFile = function (fileItem) {  // 选择文件后 （成功）   0          
        console.info('onAfterAddingFile', fileItem);
        $scope.upcengflag = true;
        if (trainupfile.isUploading) {
            $scope.isupobj.datas.queue.splice($scope.isupobj.datas.queue.length-1,1);
            MsgCon.alert("有文件正在上传。。");
            return;
        } else {

            var upfileparam = "";;
            if ($scope.dbkbids.length == 1) {
                upfileparam = "?fid=" + $scope.dbkbids[0].upId + "&orgid=" + sysUserInfo.getuserinfo().organization_ID + "&uid=" + sysUserInfo.getuserinfo().user_ID;
            } else {
                upfileparam = "?fid=0&orgid=" + sysUserInfo.getuserinfo().organization_ID + "&uid=" + sysUserInfo.getuserinfo().user_ID;
            }
            //上传文件路径
            fileItem.url = RS.uploadScrom(upfileparam);

        }
        //trainupfile.uploadAll();
    };
    trainupfile.onAfterAddingAll = function (addedFileItems) { // 选择文件后添加到队列   1 
        console.info('onAfterAddingAll', addedFileItems);
//        if ($scope.showinfo.sharequer||$scope.sosoText) {    // 共享文件时禁止上传
        if ($scope.showinfo.sharequer || $scope.showinfo.selquer || $scope.showinfo.mysharequer || $scope.showinfo.seltxt || $scope.showinfo.selweb || $scope.sosoText){
            Msg.info("此操作情况下不能上传文件！");
            trainupfile.clearQueue()
            return;
        } else {
            if (trainupfile.isUploading) {
            $scope.isupobj.datas.queue.splice($scope.isupobj.datas.queue.length-1,1);
                MsgCon.alert("有文件正在上传。。");
                return;
            } else {
                $scope.isupobj.upflag = true;
                $scope.isupobj.isbtn = true;  // 初始化   
                trainupfile.uploadAll();
            }
        }
    };
    // 开始上传
    trainupfile.onBeforeUploadItem = function (item) {    // 2 上传之前一项
        console.info('onBeforeUploadItem', item);
        if ($scope.dbkbids.length > 0) {
            item.file.pid = $scope.dbkbids[0].upId;
        } else {
            item.file.pid = 0;
        }
    };
    trainupfile.onProgressItem = function (fileItem, progress) {   // 3 上传进度
        console.info('onProgressItem', fileItem, progress);
        //        $scope.exUserList[0].import_Num = progress;    // 上传进度
        //        if (progress == 100) {    // 上传完成后改成处理中
        //            $scope.exUserList[0].import_State = "处理中";
        //        }
    };
    trainupfile.onProgressAll = function (progress) {      //4 队列进度
        console.info('onProgressAll', progress);
    };
    trainupfile.onSuccessItem = function (fileItem, response, status, headers) {   // 5上传成功
        console.info('onSuccessItem', fileItem, response, status, headers); //fileItem 请求信息 response: 返回值status: 返回状态  headers: 请求头 
        fileItem.resdata = response; //临时的
        if (response.errorcode == "0") {
            Msg.success("文件上传成功！")
            if (response.data != undefined) {
//                console.log(response.data);
                fileItem.resdata = response.data;  // 文件对象的信息         
                if($scope.dbkbids.length==0 || $scope.dbkbids[0].upId == response.data.fid){    //上传完成后判断一下是不是在此目录内。
                    $scope.kblist.push(response.data);
                }
                if (response.data.fid != "0") { // 在子集中上传的文件共享文件夹不能出来
                    $scope.showinfo.chileshow = false;
                } else { // 说明在首页
                    $scope.dbkbids = []; // 打死不能变
                }
            }
        } else if (response.errorcode == "30") {// 上传地址有问题
            Msg.info("文件上传成功，已存入同名文件的历史记录中！")
        } else if (response.errorcode == "33") {// 转换失败
            Msg.error("文件上传成功，文件转码失败！")
            if (response.data != undefined) {
//                console.log(response.data);
                fileItem.resdata = response.data;  // 文件对象的信息         
                if($scope.dbkbids.length==0 || $scope.dbkbids[0].upId == response.data.fid){    //上传完成后判断一下是不是在此目录内。
                    $scope.kblist.push(response.data);
                }
                if (response.data.fid != "0") { // 在子集中上传的文件共享文件夹不能出来
                    $scope.showinfo.chileshow = false;
                } else { // 说明在首页
                    $scope.dbkbids = []; // 打死不能变
                }
            }
        }else {
            Msg.error("文件上传异常！")
        }
    };
    trainupfile.onErrorItem = function (fileItem, response, status, headers) {     // 5上传失败
        console.info('onErrorItem', fileItem, response, status, headers);
        //        $scope.exUserList[0].import_State = "失败";
        //        MsgCon.alert("连接不上服务器");
        //trainupfile.clearQueue();
    };
    trainupfile.onCancelItem = function (fileItem, response, status, headers) {    //5取消上传
        //$scope.exUserList[0].import_State = "取消";
        console.info('onCancelItem', fileItem, response, status, headers);
    };
    trainupfile.onCompleteItem = function (fileItem, response, status, headers) {  //6     单文件上传完成
        console.info('onCompleteItem', fileItem, response, status, headers)
    };
    trainupfile.onCompleteAll = function () {  // 6 单文件上传完成或者队列上传完成的时候
        console.info('onCompleteAll');
        //trainupfile.clearQueue();  // 上传完毕清除队列
    };
    /*********************************************文件上传结束**********************************************/


    //显示控制（upshow:操作工具条   mtype:列表、图标  sososhow:搜索框 sharequer:是否共享查询 seltxt记事本 selweb网站收藏 selquer问答）
    $scope.showinfo = { "upshow": true, "mtype": "1", "sososhow": false, "sharequer": false, "chileshow": true, "mysharequer": false, "seltxt": false, "selweb": false, "selquer": false, "orgselquer": false,"orgselckt":false};
      
    //查询筛选条件
    $scope.params = { "userid": sysUserInfo.getuserinfo().user_ID, "fid": "0", "orgid": sysUserInfo.getuserinfo().organization_ID, "searchText": "", "pageIndex": "1", "pageSize": "27", "searchType": "3", "tagid": "", "fileType": "", "Shares": "", "orderby": "desc", "powerLV": sysUserInfo.getuserinfo().powerLV,"intoOrg":"" };


    $scope.sosoText = "";

    //修改选中样式（单个、全选）
    $scope.isActive = false;
    $scope.select_all = false;
    $scope.oldtype=true;
    //选中的 ID 字符串
    $scope.kbids = [];
    $scope.dbkbids = [];
    $scope.kbinfo = { "upUserId": sysUserInfo.getuserinfo().user_ID, "upOrgId": sysUserInfo.getuserinfo().organization_ID, "userName": sysUserInfo.getuserinfo().username, "fileName": "", "filepath": "/", "fid": "0", "upId": "0", "fileTxt": "" };

    //当前选中的对象
    //    $scope.selkninfo = "";
    //面包屑目录信息
    $scope.crumbsknlist = [];
    //全选/全不选
    $scope.selectAll = function () {
        $scope.dbkbids = [];
        $scope.upLoadingShow = true;
        if ($scope.select_all) {
            $scope.upLoadingShow = true;
            $scope.select_all = false;
            $scope.kbids = [];
            angular.forEach($scope.kblist, function (i, index) {
                $scope.kblist[index].sel = false;
            })
            $scope.showinfo.sharequer=false;
        } else {
            $scope.select_all = true;
            $scope.kbids = [];
            angular.forEach($scope.kblist, function (i, index) {
                $scope.kbids.push(i);
                $scope.kblist[index].sel = true;
                if(i.status==2){ 
                    $scope.upLoadingShow = false;
                }
            })
            $scope.updatefilenameshow=false;
            $scope.delfileshow = true;
        }        
//        console.log($scope.kbids);
    };
    $scope.zhuanma=false;
    // 如果有选择了上传中的文件则不让上传。
    $scope.upLoadingShow = true;
    //单个checkbox选择
    $scope.selcheck = function (selid) {
        
        $scope.upLoadingShow = true;
        //        $scope.dbkbids = [];
        //        $scope.selkninfo = selid; //记录点击对象
        angular.forEach($scope.kblist, function (i, id) {            
            //遍历判断checkbox是否已选
            if ($scope.kblist[id].upId == selid.upId) {
                //var index = $scope.kbids.indexOf(selid.upId);
                var index = $scope.containskdList($scope.kbids, selid);
                if (index == -1) {
                    if($scope.kblist[id].status==1){
                        $scope.zhuanma=true;
                    }
                    $scope.kbids.push(selid);
                    $scope.kblist[id].sel = true;
                    //$scope.dbkbids.push(selid);
                } else if (index != -1) {
                    $scope.kbids.splice(index, 1);
                    $scope.kblist[id].sel = false;
                }
            }
        });
        angular.forEach($scope.kbids,function(item, id){                   
           // 只要有一个是上传中的则隐藏所有的操作
            if(item.status==2){ 
                $scope.upLoadingShow = false;
            }        
        });
        if($scope.upLoadingShow){$scope.upLoadingShow = true}
        if ($scope.kblist.length === $scope.kbids.length) {
            $scope.select_all = true;
        } else {
            $scope.select_all = false;
        }


        if ($scope.showinfo.sharequer) {
            //查询用户是有权限 删除/修改
            RS.getfileShare({ fileid: selid.upId, shareid: sysUserInfo.getuserinfo().user_ID }).then(function (datashare) {
                if (datashare.errorcode == "0") {
//                    console.log(datashare.datas);
                    for (var i = 0; i < datashare.datas.length; i++) {
                        if (datashare.datas[i].sharetype == 0) {
                            $scope.delfileshow = false;
                            $scope.updatefilenameshow = false;
                        }
                    }
                }
            });
        } else {
            $scope.delfileshow = true;
            if (selid.fileType == "folder" || $scope.kbids.length > 1) {    //文件夹禁止下载            
                $scope.downloadshow = false;
            }
            if ($scope.kbids.length == 1 && $scope.kbids[0].fileType != "folder") {    // 可以下载            
                $scope.downloadshow = true;
            }

            if ($scope.kbids.length > 1) {  // 文件重命名的显示隐藏
                $scope.updatefilenameshow = false;
                $scope.zhuanma=false;
            } else {
                $scope.updatefilenameshow = true;
                if($scope.kbids.length==1 && $scope.kbids[0].status==1){
                    $scope.zhuanma=true;
                }else{
                    $scope.zhuanma=false;
                }
            }
        }

        if($scope.kbids.length >0 &&$scope.kbids.length <=1 && $scope.kbids[0].fileType.toLowerCase() =="ckt"){
            $scope.showinfo.orgselckt = true;
        }else{
            $scope.showinfo.orgselckt = false;
        }
        //        console.log($scope.kbids);
    }

    Array.prototype.baoremove = function (dx) {
        if (isNaN(dx) || dx > this.length) { return false; }
        this.splice(dx, 1);
    }
    //文件预览
    $scope.isfilepreview = { divhide: false, data: "",filepath:[] };

    $scope.filelist = function () {
        //        $scope.kbids=[];
        $scope.params.pageIndex = 1;
        $scope.params.fid = $scope.kbids[0].fid;
        $scope.knList();
    }
    

    //双击查看下一级目录
    $scope.dbselkb = function (kbinfo) {
        // 判断文档是否在转换中
        if(kbinfo.status == 4){
            Msg.info("文件正在进行转码，转码中可能文件不能正常访问请耐心等待");            
        }
        //判断文件是否上传中        
        if(kbinfo.status == 2){
            Msg.warning("文件正在上传中请稍后。。。");
            return;
        }
        $scope.params.tagid = "";
        $scope.params.Shares = "";
        $scope.showinfo.sososhow = false;
        $scope.select_all = false;
//        console.log("双击");
        //文件夹双击查看下一级、文件双击打开或预览
        if (kbinfo.fileType.toLowerCase() == "folder") {
            //$scope.oldtype = false; // 隐藏ul列表容器
			$scope.showinfo.chileshow= false;
            $scope.isloading = true;
            $scope.kblist = [];
            $scope.dbkbids = [];
            $scope.dbkbids.push(kbinfo);
            $scope.params.searchText = "";
            $scope.sosoText = "";
            $scope.kblist = "";
            $scope.kbids = [];
            //共享文件里面
            if($scope.discon.disnewfile){
                $scope.shareparam.fid=kbinfo.upId;
                $scope.sharedfolder();  
            }else{
                $scope.params.pageIndex = 1;
                $scope.params.fid = kbinfo.upId;
                $scope.params.fileType = "";
                $scope.knList();
            }
            //            $scope.selkninfo = kbinfo; //记录点击对象

            if ($scope.crumbsknlist.length == 0) {
                $scope.crumbsknlist.push(kbinfo);
            } else {
                var flag = false; var del_index = 0;
                for (var i = 0; i < $scope.crumbsknlist.length; i++) {
                    if ($scope.crumbsknlist[i].upId == kbinfo.upId) {
                        del_index = i;
                        flag = true;
                    }
                }
                if (flag) {
                    for (var i = $scope.crumbsknlist.length - 1; i > del_index; i--) {
                        $scope.crumbsknlist.baoremove(i);
                    }
                    //$scope.crumbsknlist=$scope.cknlist.splice(1,$scope.cknlist.length-del_index) ;
                } else {

                    $scope.crumbsknlist.push(kbinfo);
                }
            }            
//        } else if (kbinfo.fileType.toLowerCase() == "ckt") {            
//            //跳转课件预览
//            //window.open(kbinfo.fileurlonly);
//            //$scope.editckt(kbinfo.upId);
//            $scope.filepreview(kbinfo);
        } else if (kbinfo.fileType.toLowerCase() == "ques") {
            $scope.selectshowanswer(kbinfo);
        } else if (kbinfo.fileType.toLowerCase() == "wxt") {
            $scope.kbinfo = kbinfo;
            $scope.notenochang=kbinfo.fileTxt;
            $scope.shownotepad = true;
            $scope.uuid=kbinfo.upId;
        } else if (kbinfo.fileType.toLowerCase() == "urls") {
            $scope.kbinfo = kbinfo;
             $scope.weburlnochang=kbinfo.fileurlonly;
            $scope.webnamenochang=kbinfo.fileName;
            $scope.showcollection = true;
        } else {
            $scope.filepreview(kbinfo);
        }
    }
    //页面监听预览页面
    $scope.$watch('previewobj', function (newValue, oldValue, scope) {
//        console.log($scope.sysknow.orderby);
        if (newValue != oldValue && newValue != '' && newValue != undefined && newValue != null) {
            $scope.filepreview(newValue);
        }
    }, true);
    //预览
    $scope.filepreview = function (kbinfo) {
        if (kbinfo == undefined) {
            kbinfo = $scope.kbids[0];
        }

        if (kbinfo.previewNumber == undefined || kbinfo.previewNumber == NaN) {
            kbinfo.previewNumber = 1;
        } else {
            kbinfo.previewNumber = parseInt(kbinfo.previewNumber) + 1;
        }

        if (kbinfo.fileType == "wxt") {
            $scope.kbinfo = kbinfo;
            $scope.shownotepad = true;
        } else if (kbinfo.fileType == "urls") {
            $scope.kbinfo = kbinfo;
            $scope.showcollection = true;
        } else if (kbinfo.fileType == "ques") {
            $scope.kbinfo = kbinfo;
            if (typeof ($scope.quesinfo.fileTxt) == "string") {
                $scope.quesinfo.fileTxt = JSON.parse($scope.quesinfo.fileTxt);
            }
            //$scope.quesinfo.fileTxt = JSON.parse(kbinfo.fileTxt);
            $scope.showanswer = true;
        } else {
            //集合修改浏览器次数
            $scope.kblist.forEach(function (kbinfo1, index) {
                if (kbinfo1.upId == kbinfo.upId) {
                    $scope.kblist.splice(index, 1, kbinfo);
                }
            });

            $scope.pvparams = { fileid: kbinfo.upId, orgid: sysUserInfo.getuserinfo().organization_ID, userid: sysUserInfo.getuserinfo().user_ID, previewNumber: kbinfo.previewNumber };
            RS.PreviewNumber($scope.pvparams).then(function (kbdata) {
                if (kbdata.errorcode == "0") {

                } else {
                    //console.log(kbdata.errorcode);
                }

            });

            if (kbinfo == undefined) { kbinfo = $scope.kbids[0]; }
            $scope.isfilepreview.divhide = true;
            // 要调整的地址” 
            if (!(kbinfo.filepreview == null || kbinfo.filepreview == undefined || kbinfo.filepreview == "")) {
                if (kbinfo.filepreview.indexOf('8189/Fast-Trianing-FileCenter') < 0) {
                    kbinfo.filepreview = kbinfo.filepreview.replace('8189', '8189/Fast-Trianing-FileCenter');
                }
            }
            $scope.isfilepreview.data = kbinfo;
        }
    }


    //修改列表模式
    $scope.mtype = function () {
        //$scope.kbids = [];
        // $scope.select_all = true;
        // $scope.selectAll();
        if ($scope.showinfo.mtype == "1") {
            $scope.showinfo.mtype = "0";
            $scope.isActive = true;
        } else {
            $scope.showinfo.mtype = "1";
            $scope.isActive = false;
        }
    }

    //    ng-mouseover="showMsg(2)" ng-mouseleave="hideMsg(2)"

    $scope.abc = { "filedown": false, "filemove": false, "filecopy": false, "filedel": false, "filemore": false, "filediv": false };

    $scope.showMsg = function (kdtype) {
        switch (kdtype) {
            case 1: $scope.abc.filedown = true; break;
            case 2: $scope.abc.filemove = true; break;
            case 3: $scope.abc.filecopy = true; break;
            case 4: $scope.abc.filedel = true; break;
            case 5: $scope.abc.filemore = true; break;
            default: break;
        }
    }

    $scope.hideMsg = function (kdtype) {
        switch (kdtype) {
            case 1: $scope.abc.filedown = false; break;
            case 2: $scope.abc.filemove = false; break;
            case 3: $scope.abc.filecopy = false; break;
            case 4: $scope.abc.filedel = false; break;
            case 5: $scope.abc.filemore = false; break;
            default: break;
        }
    }

    $scope.showfilediv = function () {
        $scope.abc.filediv = true;
    }


    $scope.soushuo = function () {
        $scope.showinfo.sososhow = true;
    }
    //搜索
    $scope.filterkn = function () {
        $scope.isloading = true;
        $scope.params.tagid = "";
        //$scope.params.fileType = "";
        $scope.kblist = "";
        $scope.kbids = [];
        $scope.crumbsknlist = [];
        $scope.dbkbids = [];
        $scope.params.pageIndex = 1;

        if ($scope.showinfo.sharequer && $scope.params.Shares == "0") {
            $scope.knList();
        } else if ($scope.showinfo.sharequer) {
            $scope.shareparam.searchText = $scope.params.searchText;
            $scope.sharedfolder();
        } else {
            $scope.knList();
        }
    }

    $scope.isloading = false; //数据加载
    $scope.isbtnload = false; //保存按钮


    //查看全部文件
    $scope.selectAllkn = function () {
        $scope.showinfo.sharequer=true;
        $scope.divoption("all");
        $scope.select_all = false;
        $scope.comFun = false;
        $scope.params.tagid = "";
        $scope.kblist = "";
        $scope.kbids = [];
        $scope.dbkbids = [];
        $scope.params.fid = "0";
        $scope.params.pageIndex = 1;
        $scope.params.searchText = "";
        $scope.params.Shares = "";
        $scope.sosoText = "";
        $scope.isloading = true;
        $scope.params.fileType = "";
        $scope.knList();

        //当前选中的对象
        //        $scope.selkninfo = "";
        //面包屑目录信息
        $scope.crumbsknlist = [];

        $scope.kbinfo.fileName = "";
        $scope.kbinfo.filepath = "/";
        $scope.kbinfo.fid = "0";
        $scope.kbinfo.upId = "0";
    }
    //查看记事本文件
    $scope.selectTxt = function () {
        $scope.divoption("seltxt");
        $scope.select_all = false;        
        $scope.params.tagid = "";
        $scope.kblist = "";
        $scope.kbids = [];
        $scope.dbkbids = [];
        $scope.params.pageIndex = 1;
        $scope.params.searchText = "";
        $scope.params.Shares = "";
        $scope.comFun = true;
        $scope.comName = "记事本";
        $scope.sosoText = "";
        $scope.isloading = true;
        $scope.params.fileType = "wxt";
        $scope.knList();

        //当前选中的对象
        //        $scope.selkninfo = "";
        //面包屑目录信息
        $scope.crumbsknlist = [];
        $scope.kbinfo.fileName = "";
        $scope.kbinfo.filepath = "/";
        $scope.kbinfo.upId = "0";
    }
    //查看网页收藏
    $scope.selectWeb = function () {
        $scope.divoption("selweb");
        $scope.select_all = false;
        $scope.params.tagid = "";
        $scope.kblist = "";
        $scope.kbids = [];
        $scope.dbkbids = [];
        $scope.params.pageIndex = 1;
        $scope.params.searchText = "";
        $scope.params.Shares = "";
        $scope.comFun = true;
        $scope.comName = "网页收藏";
        $scope.sosoText = "";
        $scope.isloading = true;
        $scope.params.fileType = "urls";
        $scope.knList();

        //当前选中的对象
        //        $scope.selkninfo = "";
        //面包屑目录信息
        $scope.crumbsknlist = [];

        $scope.kbinfo.fileName = "";
        $scope.kbinfo.filepath = "/";
        $scope.kbinfo.upId = "0";
    }
    //查看问答
    $scope.selectQuestion = function () {
        $scope.divoption("selque");
        $scope.select_all = false;        
        $scope.params.tagid = "";
        $scope.kblist = "";
        $scope.kbids = [];
        $scope.dbkbids = [];
        $scope.params.pageIndex = 1;
        $scope.params.searchText = "";
        $scope.params.Shares = "";
        $scope.comFun = true;
        $scope.comName = "问答";
        $scope.sosoText = "";
        $scope.isloading = true;
        $scope.params.fileType = "ques";
        $scope.knList();

        //当前选中的对象
        //        $scope.selkninfo = "";
        //面包屑目录信息
        $scope.crumbsknlist = [];

        $scope.kbinfo.fileName = "";
        $scope.kbinfo.filepath = "/";
        $scope.kbinfo.upId = "0";
    }
     //查看课件制作工具
    $scope.selectCkt = function () {
        $scope.divoption("selweb");
        $scope.select_all = false;        
        $scope.params.tagid = "";
        $scope.kblist = "";
        $scope.kbids = [];
        $scope.dbkbids = [];
        $scope.params.pageIndex = 1;
        $scope.params.searchText = "";
        $scope.params.Shares = "";
        $scope.comFun = true;
        $scope.comName = "问答";
        $scope.sosoText = "";
        $scope.isloading = true;
        $scope.params.fileType = "ckt";
        $scope.knList();

        //当前选中的对象
        //        $scope.selkninfo = "";
        //面包屑目录信息
        $scope.crumbsknlist = [];

        $scope.kbinfo.fileName = "";
        $scope.kbinfo.filepath = "/";
        $scope.kbinfo.upId = "0";
    }
    //我的共享
    $scope.myShare = function () {
        $scope.divoption("myshare");
        $scope.isloading = true;
        $scope.params.tagid = "";
        $scope.kblist = "";
        $scope.kbids = [];
        $scope.dbkbids = [];
        $scope.params.fid = "0";
        $scope.params.pageIndex = 1;
        $scope.params.searchText = "";
        $scope.params.Shares = "0";
        $scope.sosoText = "";
        $scope.params.fileType = "";
        $scope.knList();

        //当前选中的对象
        //        $scope.selkninfo = "";
        //面包屑目录信息
        $scope.crumbsknlist = [];

        $scope.kbinfo.fileName = "";
        $scope.kbinfo.filepath = "/";
        $scope.kbinfo.fid = "0";
        $scope.kbinfo.upId = "0";
    }
     // 问答题查询处理
     $scope.quesHand =function(list){
                // 问答题处理
                angular.forEach(list,function(data,index){
                    if(data.fileType == "ques")
                    if(data.fileTxt == undefined || data.fileTxt == null || data.fileTxt == ""){
                        data.fileTxt = [];
                    }else{
                        data.fileTxt = JSON.parse(data.fileTxt);
                    }                    
                })
     }
     $scope.kblistcopy=[];     
    //知识库列表查询
    $scope.knList = function () {
        $scope.kblistcopy=[];
        if($scope.discon.disnewfile==true){
            $scope.params.intoOrg=1;
        }else{
			$scope.params.intoOrg="";
		}
        RS.getuserfile($scope.params).then(function (kbdata) {
            $scope.isloading = false;
            //$scope.oldtype = true;// 显示ul列表内容容器c
            if (kbdata.errorcode == "0") {
                if (kbdata.datas.length > 0) {                    
                    $scope.showinfo.upshow = false;
                }
                $scope.showinfo.upshow = false;
                $scope.kblist = kbdata.datas;
                $scope.quesHand($scope.kblist);
                
                $scope.kblistcopy=angular.copy($scope.kblist);
                if ($scope.kbids.length > 0) {
                    $scope.kblist.forEach(function (kbinfo, index) {
                        if (kbinfo.upId == $scope.kbids[0].upId) {
                            kbinfo.sel = true;
                            $scope.kblist.splice(index, 1, kbinfo);
                        }
                    });
                }
                $scope.paginationConf.totalItems = kbdata.numCount;
                $scope.paginationConf.currentPage = kbdata.pageIndex;
            } else {
                Msg.error("请求数据服务器异常！");
            }
        }, function callback() {
            Msg.error("请求数据异常！");
        });
    }


    //分页
    $scope.paginationConf = {
        currentPage: 1, //$location.search().currentPage ? $location.search().currentPage :
        totalItems: 0,
        itemsPerPage: 27,
        //pagesLength: 10,
        perPageOptions: [27,54],
        //rememberPerPage: 'perPageItems',
        onChange: function () {
        if( (parseInt($scope.params.pageIndex) !=parseInt($scope.paginationConf.currentPage))||(parseInt($scope.params.pageSize) !=parseInt($scope.paginationConf.itemsPerPage))){
                if ($scope.paginationConf.currentPage == 0) { $scope.paginationConf.currentPage = 1; }                
                $scope.params.pageIndex = $scope.paginationConf.currentPage;
                $scope.params.pageSize = $scope.paginationConf.itemsPerPage;
                if($scope.showinfo.orgselquer || $scope.showinfo.sharequer){ // 外部// 企业共享                                                    
                    if($scope.showinfo.orgselquer){ // 企业外部文件夹
                        $scope.orgsharedfolder();
                    }else{
                        $scope.sharedfolder();                
                    }            
                }else{                                                    
                    //        筛选类型（1.文件名称2.文件大小3.文件上传时间4.文件修改时间）
                    $scope.knList();
                }         
            }            
        }
    }

   // 删除信息框的显示隐藏    
    $scope.deleteHide = false; //隐藏状态
    // 隐藏 用于指令回调
    $scope.cancelHide = function(){
        $scope.deleteHide = false; 
    }
    $scope.delitem=null;
    //删除知识库文件/文件夹
    $scope.delkn = function (kbinfo,index) {
         if(index==0 || index=="0"||index==undefined||index==null||index==""){
            $scope.delitem=kbinfo;
             index="0"
        }else{
            kbinfo=$scope.delitem;
        }
        //if($scope.showinfo.mtype==0){
//        if ($scope.isfileattr.divhide) {
            if (kbinfo != undefined) {$scope.kbids = [];$scope.kbids.push(kbinfo);}$scope.kbids[0].sel=true;
            
//        }

        $scope.delparam = { "fileid": "", "userId": sysUserInfo.getuserinfo().user_ID, "orgId": sysUserInfo.getuserinfo().organization_ID,"confirmdel":index };
        if ($scope.kbids.length <= 0) {
            MsgCon.alert('请选择一条记录！');
        } else {
                 var fileids = ""; //拼接多个文件ID
                            for (var i = 0; i < $scope.kbids.length; i++) {
                                if (fileids == "") {
                                    fileids += $scope.kbids[i].upId;
                                } else {
                                    fileids += "," + $scope.kbids[i].upId;
                                }
                            }
                            $scope.delparam.fileid = fileids;
                  if(index==0||index=="0"){
                         MsgCon.delnoicon().then(function (flag) {   // 删除弹框
                        if (flag) {
                            $scope.delcenter($scope.delparam);//调用删除
                        }
                    }, function callback() {
                        Msg.error("请求数据异常！");
                    });
                  //删除关系       
                  }else if(index==1||index=="1"){
                        $scope.delcenter($scope.delparam);
                   //删除全部
                  }else{
                     //提示框
                    MsgCon.delnoicon("删除提示","删除的数据将永久丢失，不可找回，确定删除吗？").then(function (flag) {   // 删除弹框
                        if (flag) {
                            $scope.delcenter($scope.delparam);
                        }
                    })
                  }
        }
        //        console.log($scope.kbids);
    }

    $scope.delcenter=function(param){
     //删除数据提交
        RS.delfile(param).then(function (kbdata) {
                        $scope.isfileattr.divhide = false;
                        if (kbdata.errorcode == 0) {
                            Msg.success("删除成功");
                            // 更新企业基本信息
                            sysUserInfo.getOrgDetails();
                             $scope.delitem=null;
                             $scope.deleteHide = false; 
                             for (var i = 0; i < $scope.kbids.length; i++) {
                                //集合中移除删除的文件
                                $scope.kblist.forEach(function (kbinfo, index) {
                                    if (kbinfo.upId == $scope.kbids[i].upId) {
                                        $scope.kblist.splice(index, 1);
                                    }
                                });
                            }
							
                            $scope.kbids = [];
                            $scope.select_all = false;
                            if ($scope.kbids[0].fid == "0") {
                                $scope.dbkbids = [];
                            } else {
                                $scope.showinfo.chileshow = false; // 在文件夹内不能显示企业文件夹
                            }
                            //                            $scope.kblist = "";
                            //                            $scope.kbids = [];
                            //                            $scope.dbkbids = [];
                            //                            $scope.params.pageIndex = 1;
                            //                            $scope.knList();
                        } else if (kbdata.errorcode == "34") {   // 获取失败 
                                    //Msg.warning("该知识架构已关联：" + response.errormsg + "课程");                                                
                                    $scope.deleteList = kbdata.datas;
                                    $scope.deleteHide = true;   // 显示关联窗口
                         } else {
                            console.log("删除异常代码:" + kbdata.errorcode);
                        }
                    });
    }
    /********************************文档转码**********************************/
     $scope.upCodeFile=function(){
        var list=[];//要转码的文件
        $scope.kbids.forEach(function(data,index){
            var type=data.fileType.toLowerCase();
            if(type=="doc"||type=="docx"||type=="ppt"||type=="xls"||type=="xlsx"||type=="pptx"){
                list.push({id:data.upId,url:data.fileurlonly});
            }
        });
        if(list.length<=0){
            Msg.warning("请选择要转码的文档（只限文档）！");
            return;
        }
//         getAjax(commonFileUrl + "/file/fileTranscod", {data:JSON.stringify(list)}, function (response) {
//            if (response.errorcode == 0) {/// <reference path="../class/" />

//                Msg.success("请求成功，已开始重新转码！");
//            }else {
//                    console.log("转码异常代码:" + response.errorcode);
//            }
//        },function(e){
//            Msg.error("网络异常！");
//        });
        $.ajax({
            type: 'post',
            dataType: 'json',
            url: commonFileUrl+ "/file/fileTranscod",
            data: {data:JSON.stringify(list)},
            cache: false,
            async: true,
            success: function (msg) {
                 Msg.success("请求成功，已开始重新转码！");
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log("转码异常代码:");
            }
        });

    }
    /*********************************文件移动********************************************************/
    $scope.mvparams = { "fileid": "", "fid": "0", "fpath": "", "ctype": "", "userId": sysUserInfo.getuserinfo().user_ID, "orgId": sysUserInfo.getuserinfo().organization_ID };
    $scope.commenID=0;
    $scope.ParentData = { "kdids": "", "fpath": "", "knshow": false, "optype": "", "loading": false,"commenId":"" };
    $scope.movefile = function (kbinfo) {
        $scope.ParentData.isbtnload = false;
//        if ($scope.showinfo.mtype == 0) {            
            if (kbinfo != undefined) { $scope.kbids = [];$scope.kbids.push(kbinfo); }$scope.kbids[0].sel=true;
//        }
        $scope.mvparams.fileid="";
           $scope.ParentData.commenId=[];
        if ($scope.kbids.length > 1) {
             for (var i = 0; i <$scope.kbids.length; i++) {
                if(i==0){
                     $scope.mvparams.fileid += $scope.kbids[i].upId;
                }else{
                       $scope.mvparams.fileid +=","+$scope.kbids[i].upId;
                }
                $scope.ParentData.commenId.push($scope.kbids[i].upId);
            }     
        }else if($scope.kbids.length > 5){
            Msg.info("操作文件数不能大于5个！");
        } else {
            $scope.mvparams.fileid = $scope.kbids[0].upId;
            $scope.ParentData.commenId.push($scope.kbids[0].upId);
        }
        // $scope.ParentData.commenId=$scope.kbids[0].upId;
            $scope.ParentData.optype = "2"; // "移动到此目录";
            $scope.mvparams.ctype = 2;
            $scope.ParentData.knshow = true;
    }
    //    选中的文件夹ID{{ParentData.kdids}}
    /*********************************文件复制********************************************************/
    $scope.copyfile = function (kbinfo) {
        $scope.ParentData.isbtnload = false;
//        if ($scope.showinfo.mtype == 0) {
            if (kbinfo != undefined) {$scope.kbids = []; $scope.kbids.push(kbinfo);}$scope.kbids[0].sel=true; 
//        }
         $scope.mvparams.fileid="";
         $scope.ParentData.commenId=[];
        if ($scope.kbids.length > 1) {
             for (var i = 0; i <$scope.kbids.length; i++) {
                if(i==0){
                     $scope.mvparams.fileid += $scope.kbids[i].upId;
                }else{
                       $scope.mvparams.fileid +=","+$scope.kbids[i].upId;
                }
                 $scope.ParentData.commenId.push($scope.kbids[i].upId);
            }     
        } else if($scope.kbids.length > 5){
            Msg.info("操作文件数不能大于5个！");
        } else {
            $scope.mvparams.fileid = $scope.kbids[0].upId;
             $scope.ParentData.commenId.push($scope.kbids[0].upId);
        }
            // $scope.ParentData.commenId=$scope.kbids[0].upId;
            $scope.ParentData.optype = "1"; //"复制到此目录";
            $scope.mvparams.ctype = 1;
            $scope.ParentData.knshow = true;
    }


    /*********************************文件属性********************************************************/
    $scope.fileattr = function (kbinfo) {
        if (kbinfo != undefined) {$scope.kbids = []; $scope.kbids.push(kbinfo);}$scope.kbids[0].sel=true; 
        if ($scope.kbids.length == 0 || $scope.kbids.length > 1) {
            Msg.info("只能选择一条记录操作！");
        } else {
            $scope.selkninfo = $scope.kbids[0];
            //fileAttribute.activate({ kdids: $scope.selkninfo,filepath: $scope.crumbsknlist });            
            $scope.isfileattr.divhide = true;
            $scope.isfileattr.data = $scope.selkninfo;
            $scope.isfileattr.filepath = $scope.crumbsknlist;
            $scope.isfileattr.filestyle = { "left": (document.documentElement.clientWidth - 448) / 2 + "px" };
        }
    }

    //文件排序筛选
    $scope.sysknow = { "divclass": "knowledgeright-header-right_paixu", "showflag": false, "state": "3", objinfo: [], optype: "1", "divulclass": "knowledgeright-header-right_paixu dropdown-menu", "ddicon": "&#xe6b1;", "orderby": "desc" };

    $scope.sysknow.objinfo = [{ "ddname": "文件名称", "ddvalue": "0", "ddicon": "" }, { "ddname": "文件大小", "ddvalue": "2", "ddicon": "" }, { "ddname": "文件上传时间", "ddvalue": "3", "ddicon": "" }, { "ddname": "文件修改时间", "ddvalue": "4", "ddicon": ""}];
    //页面监听排序
    $scope.$watch('sysknow.state', function (newValue, oldValue, scope) {
        $scope.kblist = "";
        $scope.kbids = [];
        if($scope.showinfo.orgselquer || $scope.showinfo.sharequer){ // 外部// 企业共享                
            $scope.shareparam = { "xid": $scope.quanxianid(), "orgid": sysUserInfo.getuserinfo().organization_ID, "searchText": "", "searchType": "3", "pageIndex": "1", "pageSize": "20", "fid": "" };
            $scope.shareparam.orderby = $scope.sysknow.orderby;
             //兼容下拉列表指令
            if ($scope.sysknow.state == 0) {
                $scope.shareparam.searchType = 3;
            } else {
                $scope.shareparam.searchType = $scope.sysknow.state;
            }            
            if($scope.showinfo.orgselquer){ // 企业外部文件夹
                $scope.orgsharedfolder();
            }else{
                $scope.sharedfolder();                
            }            
        }else{            
            //兼容下拉列表指令
            if ($scope.sysknow.state == 0) {
                $scope.params.searchType = 3;
            } else {
                $scope.params.searchType = $scope.sysknow.state;
            }            
            $scope.params.pageIndex = 1;
            $scope.params.tagid = "";
            //        筛选类型（1.文件名称2.文件大小3.文件上传时间4.文件修改时间）
            $scope.knList();
        }
    }, true);

    //页面监听排序
    $scope.$watch('sysknow.orderby', function (newValue, oldValue, scope) {
        $scope.kblist = "";
        $scope.kbids = [];
        if($scope.showinfo.orgselquer || $scope.showinfo.sharequer){ // 外部// 企业共享                
            $scope.shareparam = { "xid": $scope.quanxianid(), "orgid": sysUserInfo.getuserinfo().organization_ID, "searchText": "", "searchType": "3", "pageIndex": "1", "pageSize": "20", "fid": "" };
            $scope.shareparam.orderby = $scope.sysknow.orderby;            
            if($scope.showinfo.orgselquer){ // 企业外部文件夹
                $scope.orgsharedfolder();
            }else{
                $scope.sharedfolder();                
            }            
        }else{            
            $scope.params.orderby = $scope.sysknow.orderby;            
            $scope.params.pageIndex = 1;
            $scope.params.tagid = "";
            //        筛选类型（1.文件名称2.文件大小3.文件上传时间4.文件修改时间）
            $scope.knList();
        }        
    }, true);

    /*******************************************文件共享列表操作开始****************************************/
    // 创建文件夹
    $scope.createfolder = function () {
        if ($scope.showinfo.sharequer||$scope.sosoText) {
            Msg.info("此操作情况下不能创建文件夹！");
        } else {
            $scope.showupname = true;
            $scope.showupnamefun('新建文件夹', '新建文件夹', 0);

            if ($scope.dbkbids.length == 0) {
                $scope.kbinfo = { "upUserId": sysUserInfo.getuserinfo().user_ID, "upOrgId": sysUserInfo.getuserinfo().organization_ID, "userName": sysUserInfo.getuserinfo().username, "fileName": "", "filepath": "/", "fid": "0", "upId": "0" };
            } else {
                $scope.kbinfo = { "upUserId": sysUserInfo.getuserinfo().user_ID, "upOrgId": sysUserInfo.getuserinfo().organization_ID, "userName": sysUserInfo.getuserinfo().username, "fileName": "", "filepath": $scope.dbkbids[0].filepath + "/" + $scope.dbkbids[0].fileName, "fid": $scope.dbkbids[0].upId, "upId": "0" };
            }
        }
    }

    //文件原名称
    var filename = "";
    //重命名
    $scope.updatefilename = function (kbinfo) {
        if (kbinfo != undefined) {$scope.kbids = [];$scope.kbids.push(kbinfo);}$scope.kbids[0].sel=true;
        if ($scope.kbids.length > 1) {
            Msg.info("只能选择一条记录操作！");
        } else {
            $scope.showupname = true;
            $scope.showupnamefun('文件/文件夹重命名', '', 1);
            $scope.kbinfo = $scope.kbids[0];
            filename = angular.copy($scope.kbinfo.fileName);
        }
    }

    $scope.showupname = false;
    $scope.upsharedflag = 0;    //0  新增文件夹  1修改文件名称
    $scope.closeupname = function () {
        $scope.kbinfo.fileName = filename;
        filename = "";
        $scope.showupname = false;
        $scope.isbtnload = false;
    }

    //显示文件夹
    $scope.showupnamefun = function (title, name, flag) {
        $scope.upsharedname = name; // 修改创建文件夹名字
        $scope.upsharedtitle = title;   // 弹框标题
        $scope.upsharedflag = flag;     // 判断什么类型的弹框
        $scope.showupname = true;
    }

    //搜索查询
    $scope.upnamekeyup2 = function (e) {
        var keycode = window.event ? e.keyCode : e.which;
        if (keycode == 13) {
            console.log('执行了回车');
            $scope.filterkn();
        } else {
            $scope.sosoText = $scope.params.searchText;
        }
    }
    //重命名保存
    $scope.upnamekeyup = function (e) {
        var keycode = window.event ? e.keyCode : e.which;
        if (keycode == 13) {
            console.log('执行了回车');
            $scope.saveupname();
        }
    }
    

    //编辑/保存文件名称
    $scope.saveupname = function () {
        if ($scope.kbinfo.fileName.length == 0) {
            Msg.info("文件或文件夹名称不能为空！");
            return;
        }

        $scope.isbtnload = true;
        if ($scope.upsharedflag == 1) {// 重命名
            RS.UpFileName($scope.kbinfo).then(function (kbdata) {
                if (kbdata.errorcode == 0) {
                    $scope.showupname = false;
                    $scope.upcengflag = true;
                    Msg.success("保存成功！");
                } else if (kbdata.errorcode == 29) {
                    $scope.isbtnload = false;
                    Msg.info("文件或文件夹名称已经存在");
                } else {
                    Msg.error("操作失败！");
                }
            }, function callback() {
                Msg.error("请求数据异常！");
            });
        } else if ($scope.upsharedflag == 0) {  // 创建文件夹
            RS.CreateFolder($scope.kbinfo).then(function (kbdata) {
                $scope.isloading2 = false;
                if (kbdata.errorcode == 0) {
                    $scope.showupname = false;
                    $scope.isbtnload = false;
                    $scope.kblist.push(kbdata.data);
                    Msg.success("保存成功！");
                } else if (kbdata.errorcode == 29) {
                    Msg.info("文件或文件夹名称已经存在");
                } else {
                    Msg.error("操作失败！");
                }
            }, function callback() {
                Msg.error("请求数据异常！");
            });
        }
    }



    /*******************************************文件共享列表操作结束****************************************/

    /*******************************************标签重命名**************************************************/

    // 数据源

    $scope.upnamelist = RS.getOldTagList();
    $scope.isidshow = -1;
    $scope.uplabname = "";
    // 显示编辑窗口
    $scope.istxtshow = function (item) {
        $scope.uplabname = item.tagname;
        $scope.isidshow = item.tagid;
        //$document.on('keydown', $scope.closetxtupnamecilck);            
    }
    //监听ESC
    //    $scope.closetxtupnamecilck = function(event){
    //            if (event.keyCode === 27) {
    //                    $scope.$apply(function () {                       
    //                        $document.off('keydown', $scope.closetxtupnamecilck);
    //                        $scope.closetxtupname();
    //                    });
    //            }       
    //    }
    // 关闭名称
    $scope.closetxtupname = function () {
        $scope.isidshow = -1;
    }

    // 获取个人标签名称
    $scope.getTagList = function () {
        $scope.userparam = { userid: sysUserInfo.getuserinfo().user_ID, orgid: sysUserInfo.getuserinfo().organization_ID };
        RS.gettaglist($scope.userparam).then(function (tagdata) {
            if (tagdata.errorcode == 0) {
                //                console.log(tagdata.datas);
                //系统标签和用户标签组合
                if (tagdata.datas.length > 0) {
                    angular.forEach($scope.upnamelist, function (taginfo, index) {
                        for (var i = 0; i < tagdata.datas.length; i++) {
                            if (tagdata.datas[i].tagid == $scope.upnamelist[index].tagid) {
                                $scope.upnamelist.splice(index, 1, tagdata.datas[i]);
                            }
                        }
                    });
                }
            } else {
                Msg.error("标签加载失败！");
            }
        }, function callback() {
            Msg.error("请求数据异常！");
        });
    }

    //获取文件对应的标签
    $scope.getFileTagList = function (tagids) {
        var taglist = [];
        if (tagids != undefined && tagids != "") {
            angular.forEach($scope.upnamelist, function (taginfo, index) {
                if (tagids.indexOf($scope.upnamelist[index].tagid) >= 0) {
                    if (taglist.length >= 3) {
                        //break;   前台只显示3个标签图标
                    } else {
                        taglist.push($scope.upnamelist[index]);
                    }
                }
            });
        }
        return taglist;
    }

    //获取文件对应的标签（相应的样式）
    $scope.getFileTagClass = function (tagids) {
        var classname = "knowledgeliebiaonamemain_text";
        var taglist = [];
        if (tagids != undefined && tagids != "") {
            angular.forEach($scope.upnamelist, function (taginfo, index) {
                if (tagids.indexOf($scope.upnamelist[index].tagid) >= 0) {
                    if (taglist.length >= 3) {
                        //break;   前台只显示3个标签图标
                    } else {
                        taglist.push($scope.upnamelist[index]);
                    }
                }
            });
        }

        if (taglist.length == 1) { classname = "knowledgeliebiaonamemain_text biaoqianfirst"; }
        else if (taglist.length == 2) { classname = "knowledgeliebiaonamemain_text biaoqiansecond"; }
        else if (taglist.length == 3) { classname = "knowledgeliebiaonamemain_text biaoqianthird"; }
        return classname;
    }

    // 保存标签名称
    $scope.saveTagNameEnter = function ($event, item, name) {
        if ($event.keyCode == 13) {
            $scope.saveTagName(item, name);
        }
    }
    $scope.saveTagName = function (item, name) {

        item.tagname = name;
        $scope.isidshow = -1;
        //        console.info(item);

        $scope.taginfo = { "tagid": item.tagid, "tagname": item.tagname, "userid": sysUserInfo.getuserinfo().user_ID, "orgid": sysUserInfo.getuserinfo().organization_ID, "tagcolor": item.tagcolor };

        RS.UpTagName($scope.taginfo).then(function (kbdata) {
            console.log(kbdata);
            if (kbdata.errorcode == 0) {
                Msg.success("标签操作成功！");
            } else {
                Msg.error("标签操作失败！");
            }
        }, function callback() {
            Msg.error("请求数据异常！");
        });
    }

    //点击标签查询对应文件夹/文件
    $scope.tagsel = function (taginfo) {
//        $scope.showinfo.chileshow = false; // 在文件夹内不能显示企业文件夹
//        $scope.showinfo.sharequer=false;
//        $scope.showinfo.mysharequer=false;
        $scope.divoption("tagsel");
        $scope.crumbsknlist = [];
        $scope.params.tagid = taginfo.tagid;

        $scope.kblist = "";
        $scope.kbids = [];
        $scope.params.pageIndex = 1;
        $scope.params.fileType = "";

        $scope.knList();
        $scope.params.searchText = "";
        $scope.sosoText = "标签为 ' " + taginfo.tagname + " ' ";
    }
    //全部标签
    $scope.selectlaball = function () {
		$scope.divoption("tagsel");
        $scope.crumbsknlist = [];
        $scope.isidshow = -1;
        $scope.params.tagid = 0;
        $scope.kblist = "";
        $scope.kbids = [];
        $scope.params.pageIndex = 1;
        $scope.params.fileType = "";
        $scope.knList();
        $scope.params.searchText = "";

        $scope.sosoText = "全部标签";
    }
    /*******************************************文件重命名**************************************************/
    /*
    //移动、复制文件到主目录
    $scope.mainsay = function () {
    $scope.mvparams.fpath = "/";
    $scope.mvparams.fid = 0;
    //        if( $scope.mvparams.fid==""){
    //        //移动文件
    //            if ($scope.ParentData.optype == 2) {
    //                Msg.info("请选择要移动的文件夹");
    //            }else{
    //                Msg.info("请选择要复制的文件夹！");
    //            }
    //        }else{
    //        $scope.ParentData.loading = false;
    $scope.ParentData.isbtnload = true;
    RS.mvfile($scope.mvparams).then(function (kbdata) {
    $scope.ParentData.loading = true;
    $scope.selectAllkn();
    if (kbdata.errorcode == 0) {

    $scope.ParentData.knshow = false;
                
    //                //移动文件
    //                if ($scope.ParentData.optype == 2) {
    //                    $scope.kblist.splice($scope.containskdList($scope.kblist, kbdata), 1);
    //                }
                
    Msg.success("操作成功！");
    } else {
    Msg.error("操作失败！");
    }
    }, function callback() {
    Msg.error("请求数据异常！");
    });
    //        }
    }
    */

    //移动、复制文件
    $scope.selectsay = function () {
        //        console.log($scope.ParentData.kdids);
        $scope.mvparams.fpath = $scope.ParentData.fpath;
        $scope.mvparams.fid = $scope.ParentData.kdids;
        
        if ($scope.mvparams.fid == "") {
            //移动文件
            if ($scope.ParentData.optype == 2) {
                Msg.info("请选择要移动的文件夹");
            } else {
                Msg.info("请选择要复制的文件夹！");
            }
        } else {
        
        if($scope.kbids[0].fid==$scope.mvparams.fid){
            Msg.info("文件或文件夹已存在此目录！");
            return;
        }

            //        $scope.ParentData.loading = false;
            $scope.ParentData.isbtnload = true;
            RS.mvfile($scope.mvparams).then(function (kbdata) {
                $scope.ParentData.loading = true;
                $scope.selectAllkn();
                if (kbdata.errorcode == 0) {
                    $scope.ParentData.knshow = false;

                    //                //移动文件
                    //                if ($scope.ParentData.optype == 2) {
                    //                    $scope.kblist.splice($scope.containskdList($scope.kblist, kbdata), 1);
                    //                }

                    Msg.success("操作成功！");
                } else {
                    Msg.error("操作失败！");
                }
            }, function callback() {
                Msg.error("请求数据异常！");
            });
        }
    }

    //检测数据是否存在数组中
    $scope.containskdList = function (arr, obj) {
        try {
            var i = arr.length;
            while (i--) {

                if (arr[i].upId === obj.upId) {
                    return i;
                }
            }
            return -1;
        } catch (e) {
            // statements
            return -1;
        }
    }

    //文件下载
    $scope.play = function (kbinfo) {        
        if (kbinfo != undefined) {$scope.kbids = [];$scope.kbids.push(kbinfo);}$scope.kbids[0].sel=true;
        if ($scope.kbids.length <= 0) {
            MsgCon.alert('请选择一条记录！');
        } else if ($scope.kbids.length > 1) {
            Msg.info("只能选择一条记录操作！");
        } else {
            if ($scope.kbids[0].fileType == "folder") {

            } else {
                window.open(RS.downloadfile("?id=" + $scope.kbids[0].upId + "&type=1"));
            }
        }
    }
    /**********************课件工具相关开始*************************/
    $scope.ckturl ="";
    var guidS4 = new GUID();
    //新增课件    
    $scope.newckt=function(){        
        var ckturl = "/wk/index.html?callback="+commonUrl+"/Kapi/AddEditURLCollection"
        var user = sysUserInfo.getuserinfo();
        var orgid =user.organization_ID;
        var canshu = "&type=0&key="+guidS4.newGUID();
        canshu +="&fid="+$scope.params.fid;//父级ID
        canshu +="&fpath=/";//显示路径
        canshu +="&upOrgId="+orgid+"&uid="+orgid+"";//企业ID
        canshu +="&upUserId="+user.user_ID;//用户ID
        canshu +="&upUserName="+encodeURI(encodeURI(user.user_Name));//用户名（编码）
        //console.log(ckturl+canshu);
        MsgCon.delnoicon("提示", "添加完毕", "", "确定", "取消").then(function (data) {
            if (data)
                $scope.knList();                   
        });
        $scope.ckturl = ckturl + canshu;             
    }
    $scope.editckt= function(key){
        var ckturl = "/wk/index.html?callback="+commonUrl+"/Kapi/AddEditURLCollection"
        //点击编辑课件
        var user = sysUserInfo.getuserinfo();
        var orgid =user.organization_ID;
        var canshu = "&type=1&key="+key;
        canshu +="&fid="+$scope.params.fid;//父级ID
        canshu +="&fpath=/";//显示路径
        canshu +="&upOrgId="+orgid+"&uid="+orgid+"";//企业ID
        canshu +="&upUserId="+user.user_ID;//用户ID
        canshu +="&upUserName="+encodeURI(encodeURI(user.user_Name));//用户名（编码）
        console.log(canshu);        
        window.open(ckturl + canshu);
        MsgCon.delnoicon("提示", "编辑完毕", "", "确定", "取消").then(function (data) {
            if (data)
                $scope.knList();                   
        });
    }
    
    
    /**********************课件工具相关结束*************************/
    /******************************************网址收藏********************************************/

    $scope.showcollection = false;
    // 收藏网址
    $scope.whereComeweb = 0;
    $scope.collectionweb = function () {
        if ($scope.showinfo.sharequer||$scope.sosoText) {
            Msg.info("此操作情况下不能收藏网址！");
        } else {
            $scope.whereComeweb = 1;
            $scope.kbinfo.filepath = "";
            $scope.showcollection = true;
            if ($scope.dbkbids.length == 0) {
                $scope.kbinfo = { "upUserId": sysUserInfo.getuserinfo().user_ID, "upOrgId": sysUserInfo.getuserinfo().organization_ID, "upUserName": sysUserInfo.getuserinfo().username, "fileName": "", "fileurlonly": "", "fid": "0", "upId": "0" };
            } else {
                $scope.kbinfo = { "upUserId": sysUserInfo.getuserinfo().user_ID, "upOrgId": sysUserInfo.getuserinfo().organization_ID, "upUserName": sysUserInfo.getuserinfo().username, "fileName": "", "fileurlonly": "", "fid": $scope.dbkbids[0].upId, "upId": $scope.dbkbids[0].UpId };
            }
        }
    }

    //编辑/保存收藏网址
    $scope.saveweb = function (flag) {
        if(!flag){
            Msg.info("验证失败或存在空值！");
            return;
        }
        if ($scope.kbinfo.fileurlonly == null || $scope.kbinfo.fileurlonly == "") {
            Msg.info("收藏网址链接不能为空！");
            return;
        }
        if ($scope.kbinfo.fileName == null || $scope.kbinfo.fileName == "") {        
            Msg.info("收藏网址名称不能为空！");
            return;
        }
        $scope.isbtnload = true;
        RS.AddEditURLCollection($scope.kbinfo).then(function (kbdata) {
            $scope.isloading2 = false;
            if (kbdata.errorcode == 0) {
                $scope.showcollection = false;
                $scope.upcengflag = true;
                $scope.isbtnload = false;
                if ($scope.whereComeweb == 1) {
                    $scope.kblist.push(kbdata.data);
                    $scope.whereComeweb = 0;
                }
                Msg.success("保存成功！");
            } else if (kbdata.errorcode == 29) {
                Msg.info("网页名称已经存在");
            } else if (kbdata.errorcode == 39) {
                Msg.warning("警告", "存储空间超过最大限制");
            } else {
                Msg.error("操作失败！");
            }
        }, function callback() {
            Msg.error("请求数据异常！");
        });
    }

    $scope.closecollection = function () {
        $scope.showcollection = false;
        $scope.kbinfo.fileurlonly=$scope.weburlnochang;
        $scope.kbinfo.fileName=$scope.webnamenochang;
    }
    /******************************************添加记事本-----编辑********************************************/
    $scope.configbtnjishiben= ['undo', 'redo', '|','bold', 'underline', 'italic', 'strikethrough','eraser','forecolor', '|',  'quote','fontsize', 'head','unorderlist','orderlist', 'alignleft', 'aligncenter','alignright', '|', 'img','insertcode', ];
    $scope.whereComeNo = 0; //判断是从新增来，还是编辑
    $scope.shownotepad = false; //记事本
    var guid = new GUID();//生成GUID
     $scope.addnotepad = function () {
        if ($scope.showinfo.sharequer) {
            Msg.info("查看共享文件时不能添加记事本！");
        } else {
            $scope.uuid=guid.newGUID();
            $scope.whereComeNo = 1;
            $scope.kbinfo.fileTxt = "";
            $scope.shownotepad = true;
            if ($scope.dbkbids.length == 0) {
                $scope.kbinfo = { "upUserId": sysUserInfo.getuserinfo().user_ID, "upOrgId": sysUserInfo.getuserinfo().organization_ID, "upUserName": sysUserInfo.getuserinfo().username, "fileName": "", "fpath": "/", "fid": "0", "upId": $scope.uuid, "fileTxt": "", "strName": "" };
            } else {
                $scope.kbinfo = { "upUserId": sysUserInfo.getuserinfo().user_ID, "upOrgId": sysUserInfo.getuserinfo().organization_ID, "upUserName": sysUserInfo.getuserinfo().username, "fileName": "", "fpath": $scope.dbkbids[0].filepath + $scope.dbkbids[0].fileName, "fid": $scope.dbkbids[0].upId, "upId": $scope.uuid, "fileTxt": "", "strName": "" };
            }
        }
    }

    //编辑/保存添加记事本
    $scope.savenotepad = function () {
        if($scope.kbinfo.fileTxt == ""||$scope.kbinfo.fileTxt ==null) {
            Msg.info("添加记事本内容不能为空！");
            return;
        }
         $scope.kbinfo.strName = delHtmlTag($scope.kbinfo.fileTxt).substring(0, 12);
         if($scope.kbinfo.strName==""){
                $scope.kbinfo.strName = "图片文件";
         }   
         $scope.newSaveObj=angular.copy($scope.kbinfo);

        $scope.newSaveObj.fileTxt = encodeURIComponent($scope.newSaveObj.fileTxt );
        $scope.isbtnload = true;
        RS.AddNotepad($scope.newSaveObj).then(function (kbdata) {
            $scope.isloading2 = false;
            if (kbdata.errorcode == 0) {
                $scope.shownotepad = false;
                $scope.upcengflag = true;
                $scope.isbtnload = false;
                if ($scope.whereComeNo == 1) {//如果是1，从新增过来，需要放入
                    $scope.kblist.push(kbdata.data);
                    $scope.whereComeNo = 0;
                }else{
                    $scope.kbinfo.fileName=$scope.kbinfo.strName;
                }
                Msg.success("保存成功！");
                 $scope.knList();
            } else if (kbdata.errorcode == 29) {
                Msg.info("记事本名称已经存在");
            } else if (kbdata.errorcode == 39) {
                Msg.warning("警告", "存储空间超过最大限制");
            } else {
                Msg.error("操作失败！");
            }
        }, function callback() {
            Msg.error("请求数据异常！");
        });
    }

    $scope.closenotepad = function () {
        $scope.uuid="";
        $scope.shownotepad = false;
        $scope.isbtnload = false;
        $scope.kbinfo.fileTxt=$scope.notenochang;
    }
    /******************************************问答********************************************/
    $scope.configbtnwenda = [ 'bold', 'underline', 'italic','|','quote','unorderlist','orderlist','|',  'img','insertcode',];
    $scope.quesinfo = { "upUserId": sysUserInfo.getuserinfo().user_ID, "upOrgId": sysUserInfo.getuserinfo().organization_ID, "upUserName": sysUserInfo.getuserinfo().username, "fpath": "/", "fid": "0", "fileTxt": "", "asCourse": "", "userImg": "", "strName": "" };
    $scope.showquestion = false;
    // 问答
    $scope.addquestion = function () {
        if ($scope.showinfo.sharequer||$scope.sosoText) {
            Msg.info("此操作情况下不能问答！");
        } else {
            $scope.uuidques=guid.newGUID();
            $scope.whereComeques = 1;
            $scope.questionfileTxt = "";
            $scope.showquestion = true;
             if ($scope.dbkbids.length == 0) {
                $scope.kbinfo = { "upUserId": sysUserInfo.getuserinfo().user_ID, "upOrgId": sysUserInfo.getuserinfo().organization_ID, "upUserName": sysUserInfo.getuserinfo().username, "fileName": "", "filepath": "/", "fid": "0", "upId": $scope.uuidques, "fileTxt": "", "strName": "" };
            } else {
                $scope.kbinfo = { "upUserId": sysUserInfo.getuserinfo().user_ID, "upOrgId": sysUserInfo.getuserinfo().organization_ID, "upUserName": sysUserInfo.getuserinfo().username, "fileName": "", "filepath": $scope.dbkbids[0].filepath + $scope.dbkbids[0].fileName, "fid": $scope.dbkbids[0].upId, "upId": $scope.uuidques, "fileTxt": [], "strName": "" };
            }
            $scope.kbinfo.fileTxt = { "fileTxts": "", //提问
                "userImg": "", //提问人头像
                "answer": "0", //回答数量
                "asCourse": "", //关联的课程
                "close_reply": false, //是否关闭问题回答
                "attribute": []
            };
//            console.log($scope.kbinfo);
        }
    }
    /************************************修改问题**********************************************/
    $scope.showquestion2 = false;
    $scope.showaddquestion2 = function () {
        $scope.shownochang=$scope.quesinfo.fileTxt.fileTxts;
        $scope.showquestion2 = true;
        $scope.showanswer = false;
    }
     //保存修改问题
    $scope.closeuploadquestion = function () {
        if ($scope.quesinfo.fileTxt.fileTxts == null || $scope.quesinfo.fileTxt.fileTxts == "") {
            Msg.info("修改问答不能为空");
        }
        //$scope.quesinfo.strName = $scope.strName.substring(0, 12);
        if ($scope.strName == undefined || $scope.strName == null) {
            $scope.quesinfo.strName = delHtmlTag($scope.quesinfo.fileTxt.fileTxts).substring(0, 12);
        } else {
            $scope.quesinfo.strName = $scope.strName.substring(0, 12);
        }
        $scope.isbtnload = true;        
         RS.UpdateAsk($scope.quesinfo).then(function (kbdata) {
            $scope.isbtnload = false;
            $scope.isloading2 = false;
            if (kbdata.errorcode == 0) {
                Msg.success("修改成功！");
                $scope.showquestion2 = false;
                  $scope.showanswer = true;
            } else {
                Msg.error("操作失败！");
            }
        }, function callback() {
            Msg.error("请求数据异常！");
        });
        
    }

    function delHtmlTag(str) {
        if (str != undefined && str != null && str != "") {
            return str.replace(/<[^>]+>/g, ""); //去掉所有的html标记
        } else {
            return "";
        }
    }
    /**********************************************************************************/
    //编辑/保存问答
     $scope.saveques = function (questionfileTxt) {
         if (questionfileTxt == null||questionfileTxt =="") {
            Msg.info("问答不能为空！");
            return;
        }
        $scope.kbinfo.fileTxt.fileTxts =questionfileTxt;
        if ($scope.strName == undefined || $scope.strName == null) {
            $scope.kbinfo.strName = delHtmlTag( $scope.kbinfo.fileTxt.fileTxts).substring(0, 12);
            if($scope.kbinfo.strName==""){
             $scope.kbinfo.strName = "图片问题";
            }
        } else {
            $scope.kbinfo.strName = $scope.strName.substring(0, 12);
        }
//        $scope.kbinfo.asCourse = "";//是否关联课程
        $scope.kbinfo.fileTxt.userImg = sysUserInfo.getuserinfo().user_Img;
        $scope.isbtnload = true;

        RS.AddAsk($scope.kbinfo).then(function (kbdata) {
            $scope.isloading2 = false;
            if (kbdata.errorcode == 0) {
                $scope.showquestion = false;
                $scope.upcengflag = true;
                $scope.isbtnload = false;
                $scope.kblist.push(kbdata.data);
                Msg.success("保存成功！");
            } else if (kbdata.errorcode == 29) {
                Msg.info("问答名称已经存在");
            } else if (kbdata.errorcode == 39) {
                Msg.warning("警告", "存储空间超过最大限制");
            } else {
                Msg.error("操作失败！");
            }
        }, function callback() {
            Msg.error("请求数据异常！");
        });
        
    }

    $scope.closequestion = function () {
        $scope.uuidques="";
        $scope.showquestion = false;
        $scope.isbtnload = false;
    }

    $scope.closequestion2 = function () {        
        $scope.quesinfo.fileTxt.fileTxts=$scope.shownochang;
        $scope.showquestion2 = false;
        $scope.showanswer=true;
        $scope.isbtnload = false;
    }

    /******************************************弹出问答回复框********************************************/
    $scope.showanswer = false;
    $scope.hasdoclick = false;
    $scope.selectshowanswer = function (kbinfo) {
        $scope.hasdoclick = false;
        $scope.quesinfo = kbinfo;
        if (typeof ($scope.quesinfo.fileTxt) == "string") {
            $scope.quesinfo.fileTxt = JSON.parse($scope.quesinfo.fileTxt);
        }
        $scope.showanswer = true;
//        console.log($scope.quesinfo);
    }
    $scope.closeanswer = function () {
        $scope.showanswer = false;
    }
    /**************************************问答*****************************************/

    /************************************编辑回复***************************************/
    $scope.updateanswer = function (attr) {
        $scope.beforeupan=attr.answer;
        attr.buttonshow = false;
        attr.buttonshow2 = true;        
    }
    /***********************************取消编辑*****************************************/
    $scope.closeanswers = function (attr) {
  //  console.log(attr);
        attr.buttonshow2 = false;
        attr.buttonshow = true;
        $scope.hasdoclick = false;
        attr.answer=$scope.beforeupan;
    }
    /******************************************问答***************************************/
    $scope.quesinfo = { "upUserId": sysUserInfo.getuserinfo().user_ID, "upOrgId": sysUserInfo.getuserinfo().organization_ID, "upUserName": sysUserInfo.getuserinfo().username, "fpath": "/", "fid": "0", "fileTxt": "", "asCourse": "", "userImg": "", "strName": "" };
     //获取当前时间
    $scope.getdate = function () {
        var date = new Date();
        var hours= date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
        var nowdate = date.getFullYear() + "-" + date.getMonth()+1 + "-" + date.getDate() + " " + hours + ":" + minute+ ":" + second;
        return nowdate;
    }
    /***********************************保存编辑******************************************/
    $scope.saveanswer = function (attr) {
        if (attr.answer == null || attr.answer == "") {
            Msg.info("请输入回复内容");
            return;
        }
        attr.buttonshow2 = false;
        attr.buttonshow = true;
        $scope.quesinfo.fileTxt.attribute.forEach(function (objinfo, objindex) {
            if (objinfo.$$hashKey == attr.$$hashKey) {
                $scope.quesinfo.fileTxt.attribute.splice(objindex, 1);
            }
        });        
        attr.anTime = $scope.getdate();
        $scope.quesinfo.fileTxt.attribute.push(attr);
        console.log(attr);
        RS.UpdateAsk($scope.quesinfo).then(function (kbdata) {
            $scope.isloading2 = false;
            if (kbdata.errorcode == 0) {
                Msg.success("保存成功！");
                //隐藏属性框
                 attr.buttonshow2 = false;
                attr.buttonshow = true;
                $scope.hasdoclick = false;
            } else {
                Msg.error("操作失败！");
            }
        }, function callback() {
            Msg.error("请求数据异常！");
        });
    }
    /*********************************删除回复******************************************/
    $scope.deleteanswer = function (attr) {
    MsgCon.delnoicon().then(function (flag) {   // 删除弹框
                if (flag) {
            $scope.quesinfo.fileTxt.attribute.forEach(function (objinfo, objindex) {
                if (objinfo.$$hashKey == attr.$$hashKey) {
                    $scope.quesinfo.fileTxt.attribute.splice(objindex, 1);
                }
            });
            $scope.quesinfo.fileTxt.answer = ($scope.quesinfo.fileTxt.answer * 1 - 1);
             RS.UpdateAsk($scope.quesinfo).then(function (kbdata) {
                $scope.isloading2 = false;
                if (kbdata.errorcode == 0) {
                    Msg.success("删除成功！");
                    console.log($scope.quesinfo);
                     $scope.closeanswers();
                } else {
                    Msg.error("操作失败！");
                }
            }, function callback() {
                Msg.error("请求数据异常！");
            });
        }
            }, function callback() {
                Msg.error("请求数据异常！");
            });
    }
   
    //获得当前登录人id
    $scope.setLoginUserId = sysUserInfo.getuserinfo().user_ID;
    /************************************添加回复***************************************/
    $scope.mytextwd = "";
    $scope.addanswer = function () {
        // console.log($scope.mytextwd);
        if ($scope.mytextwd == null || $scope.mytextwd == "") {
            Msg.info("请输入回复内容");
            return;
        }        
        var nowdate = $scope.getdate();

        $scope.newaninfo = { "answer": $scope.mytextwd, "anName": sysUserInfo.getuserinfo().username, "anImg": sysUserInfo.getuserinfo().user_Img, "anTime": nowdate, "adopt": "0", "showThis": true, "orgid": sysUserInfo.getuserinfo().organization_ID, "userid": sysUserInfo.getuserinfo().user_ID, "buttonshow": true, "showbottonall": false, "buttonshow2": false};
        $scope.quesinfo.fileTxt.attribute.push($scope.newaninfo);
        $scope.quesinfo.fileTxt.answer = ($scope.quesinfo.fileTxt.answer * 1 + 1);
        $scope.mytextwd = null;
         RS.UpdateAsk($scope.quesinfo).then(function (kbdata) {
            $scope.isloading2 = false;
            if (kbdata.errorcode == 0) {
                Msg.success("保存成功！");   
                $scope.mytextwd = null;             
                console.log($scope.quesinfo);
            } else {
                Msg.error("操作失败！");
            }
        }, function callback() {
            Msg.error("请求数据异常！");
        });
    }
    /*******************************问答的保存 (总) ************************************/
    $scope.savequesinfo = function () {
//        console.log($scope.quesinfo);
        RS.UpdateAsk($scope.quesinfo).then(function (kbdata) {
            $scope.isloading2 = false;
            if (kbdata.errorcode == 0) {
                Msg.success("保存成功！");
                $scope.showanswer = false;
            } else {
                Msg.error("操作失败！");
            }
        }, function callback() {
            Msg.error("请求数据异常！");
        });
    }
    $scope.showbottonall = false;
    //取消==关闭
    $scope.closequesifno = function () {
        $scope.showanswer = false;
    }
    /***************************问答回复的鼠标移入移出事件***********************/
    $scope.mousein = function (attr) {
        attr.showbottonall = true;
    }
    $scope.mouseout = function (attr) {
        attr.showbottonall = false;
    }
    /************************************采纳**************************************/
    $scope.caina = function (attr) {
        if (attr.adopt == "0") {
            attr.adopt = "1";
        } else {
            attr.adopt = "0"; //未采纳
        }
        $scope.isloading2 = true;
//        $scope.hasdoclick = true;
         RS.UpdateAsk($scope.quesinfo).then(function (kbdata) {
            $scope.isloading2 = false;
            if (kbdata.errorcode == 0) {
//                Msg.success("保存成功！");
//                $scope.showanswer = false;
            } else {
                Msg.error("操作失败！");
            }
        }, function callback() {
            Msg.error("请求数据异常！");
        });
    }
    /***********************************隐藏回复***********************************/
    $scope.hiddenanswer = function (attr) {
        if (attr.showThis) {
            attr.showThis = false
        } else {
            attr.showThis = true;
        }
//     $scope.hasdoclick = true;
        $scope.isloading2 = true;
//        $scope.hasdoclick = true;
         RS.UpdateAsk($scope.quesinfo).then(function (kbdata) {
            $scope.isloading2 = false;
            if (kbdata.errorcode == 0) {
//                Msg.success("保存成功！");
//                $scope.showanswer = false;
            } else {
                Msg.error("操作失败！");
            }
        }, function callback() {
            Msg.error("请求数据异常！");
        });
    }
    /*****************************关闭此问题回复**********************************/
    $scope.checkedclick = function (quesinfo) {
        if (quesinfo.fileTxt.close_reply) {
            quesinfo.fileTxt.close_reply = false;
            console.log(quesinfo);
        } else {
            quesinfo.fileTxt.close_reply = true;
        }
        RS.UpdateAsk(quesinfo).then(function (kbdata) {
            $scope.isloading2 = false;
            if (kbdata.errorcode == 0) {
                //Msg.success("保存成功！");
            } else {
                Msg.error("操作失败！");
            }
        }, function callback() {
            Msg.error("请求数据异常！");
        });
    }
    /*****************************************************************************/
    $scope.quanxianid = function () {
        var qxid = [];
        //组织结构 ID 字符串
        if (sysUserInfo.getuserinfo().userOrgList != undefined && sysUserInfo.getuserinfo().userOrgList.length > 0) {
            for (var i = 0; i < sysUserInfo.getuserinfo().userOrgList.length; i++) {
                qxid.push(sysUserInfo.getuserinfo().userOrgList[i]["organization_ID"]);
            }
        }
        //权限 ID 字符串
        if (sysUserInfo.getuserinfo().userRoleList != undefined && sysUserInfo.getuserinfo().userRoleList.length > 0) {
            for (var i = 0; i < sysUserInfo.getuserinfo().userRoleList.length; i++) {
                qxid.push(sysUserInfo.getuserinfo().userRoleList[i]["roles_ID"]);
            }
        }
        //用户组 ID 字符串
        if (sysUserInfo.getuserinfo().userGroupList != undefined && sysUserInfo.getuserinfo().userGroupList.length > 0) {
            for (var i = 0; i < sysUserInfo.getuserinfo().userGroupList.length; i++) {
                qxid.push(sysUserInfo.getuserinfo().userGroupList[i]["userGroup_ID"]);
            }
        }
        qxid.push(sysUserInfo.getuserinfo().user_ID);
        return qxid.join(",");
    }

    //共享文件查询条件
    $scope.shareparam = { "xid": $scope.quanxianid(), "orgid": sysUserInfo.getuserinfo().organization_ID, "searchText": "", "searchType": "3", "pageIndex": "1", "pageSize": "20", "fid": "" };
    //查询企业共享文件
    $scope.sharedfolder = function (param) {
        if(param!=undefined&&param==0){
            $scope.shareparam.fid="";
            $scope.crumbsknlist=[];
        }
        //不在在外部共享文件夹里
        if(!$scope.showinfo.orgselquer){
            $scope.divoption("sharequer");
        }
        
        $scope.dbkbids = [];
        $scope.params.searchText = "";
        $scope.sosoText = "";
        $scope.kblist = "";
        $scope.kbids = [];
        $scope.params.pageIndex = 1;
        $scope.params.fileType = "";
        $scope.isloading = true;
        RS.getSharelist($scope.shareparam).then(function (kbdata) {
            $scope.isloading = false;
            if (kbdata.errorcode == 0) {
                //console.log(kbdata.datas);
                $scope.kblist = kbdata.datas;
                $scope.quesHand($scope.kblist);
            } else {
                console.log(kbdata.errorcode);
            }
        }, function callback() {
            Msg.error("请求数据异常！");
        });
    }
    //文件属性
    $scope.isfileattr = { divhide: false, data: "", filepath: [] };

    //加载开始
    $scope.getTagList();
   
    /*******************浏览模式************************/

    //浏览模式
    $scope.pretype = { "divclass": "", "showflag": false, "state": 0, objinfo: [], optype: "1", "divulclass": "knowledgeright-header-right_paixu dropdown-menu", "ddicon": "","ddstyle":{"left":"-25px"} };
    $scope.pretype.objinfo = [{ "ddname": "预览模式", "ddvalue": "2", "ddicon": "&#xe6f1;" }, { "ddname": "列表模式", "ddvalue": "3", "ddicon": "&#xe6ce;" }, { "ddname": "图标模式", "ddvalue": "0", "ddicon": "&#xe650;"}];
    
    //页面监听浏览模式  [不同模式下记录数量不一致]
    $scope.$watch('pretype.state', function (newValue, oldValue, scope) {
        $scope.knowledge_liebiao(0);
    }, true);

    $scope.knowledge_liebiao=function(divwidth){
        $scope.paginationConf.currentPage=1;        
        //$scope.mtype();
        if ($scope.pretype.state == "0") {//图标模式
//            $scope.showinfo.mtype = "0";            
            if($scope.kblistcopy.length>0){
                var newkblist=[];
                for(var i=0;i<$scope.kblistcopy.length;i++){
                    if(divwidth==1){
                        if(i==20){break;}else{newkblist.push($scope.kblistcopy[i]);}
                    }else{
                        if(i==28){break;}else{newkblist.push($scope.kblistcopy[i]);}
                    }
                }
                $scope.kblist=newkblist;
            }
            $scope.oldtype=true;
            $scope.isActive = false;
            if(divwidth==1){
                $scope.paginationConf.itemsPerPage=20;//设置记录条数
                $scope.paginationConf.perPageOptions=[20,40];
            }else{
                $scope.paginationConf.itemsPerPage=28;//设置记录条数
                $scope.paginationConf.perPageOptions=[28,56];
            }
        } else if ($scope.pretype.state == "3") {//列表模式
            if($scope.kblistcopy.length>0){
                var newkblist=[];
                for(var i=0;i<$scope.kblistcopy.length;i++){
                    if(i==10){break;}else{newkblist.push($scope.kblistcopy[i]);}
                }
                $scope.kblist=newkblist;
            }
            $scope.paginationConf.itemsPerPage=10;//设置记录条数
            $scope.paginationConf.perPageOptions=[10,20];
            $scope.isActive = true;
            $scope.oldtype=true;
        }else if ($scope.pretype.state == "2") {//预览模式
            if($scope.kblistcopy.length>0){
                var newkblist=[];
                for(var i=0;i<$scope.kblistcopy.length;i++){
                    if(i==8){break;}else{newkblist.push($scope.kblistcopy[i]);}
                }
                $scope.kblist=newkblist;
            }
            $scope.paginationConf.perPageOptions=[8,16];
            $scope.paginationConf.itemsPerPage=8;//设置记录条数
            
            $scope.oldtype=false;
        }
        }

    //不同类型的样式
    $scope.previewclass = function (obj) {
        var preclass = "";
        if (obj.fileType == "folder") {//文件夹
            preclass = "knowledgeliebiao_wenjianjia";
        } else if (obj.fileType == "ques") {//记事本、网页收藏、问答、其它：office、img、video
            preclass = "knowledgeliebiao_jishiben";             
        } else if (obj.fileType == "urls"||(obj.filecover != null && obj.filecover.length >0 )) {
            preclass = "knowledgeliebiao_wjsctp";
        } else {//记事本、网页收藏、问答、其它：office、img、video
            preclass = "knowledgeliebiao_jishiben";
        }
        return preclass;
    }


    //$scope.abc = { "filedown": false, "filemove": false, "filecopy": false, "filedel": false, "filemore": false, "filediv": false };

    $scope.showfile = function (objinfo, kdtype) {
        switch (kdtype) {
            case 1: objinfo.filedown = true; break;
            case 2: objinfo.filemove = true; break;
            case 3: objinfo.filecopy = true; break;
            case 4: objinfo.filedelete = true; break;
            case 5: objinfo.filemore = true; break;
            case 6: objinfo.fileattr = true; break;
            case 7: objinfo.filerename = true; break;
            default: break;
        }
    }

    $scope.hidefile = function (objinfo, kdtype) {
        switch (kdtype) {
            case 1: objinfo.filedown = false; break;
            case 2: objinfo.filemove = false; break;
            case 3: objinfo.filecopy = false; break;
            case 4: objinfo.filedelete = false; break;
            case 5: objinfo.filemore = false; break;
            case 6: objinfo.fileattr = false; break;
            case 7: objinfo.filerename = false; break;
            default: break;
        }
    }
    //查看更多
    $scope.filemore = function (objinfo) {
        if (objinfo.filemore2) { objinfo.filemore2 = false; } else { objinfo.filemore2 = true; }
    }
    //获取问答的文字
    $scope.getfiletext=function(obj){
        if(obj.fileTxts==undefined){  
            return delHtmlTag(JSON.parse(obj).fileTxts);
        }else{
            return  obj.fileTxts;
        }
    }

    $scope.divnotepad={"margin-top": (document.documentElement.clientHeight-610)/2+"px"};//记事本、问答div位置
    $scope.divselweb={"margin-top": "12%"}; //网站收藏div位置
    //console.log(document.documentElement.clientHeight+"_"+document.documentElement.offsetHeight+"_"+document.documentElement.scrollHeight);

    //控制变量值，控制对应div的显示和隐藏
    $scope.divoption=function(obj){
        if(obj=="all"){ //全部
            $scope.discon={"disnewfile":false,"disupfile":false};
            $scope.showinfo = {  "sososhow": false,"sharequer": false, "chileshow": true, "mysharequer": false, "seltxt": false, "selweb": false, "selquer": false, "orgselquer": false,"orgselckt":false };
        }else if(obj=="myshare"){ //我的共享
            $scope.discon={"disnewfile":true,"disupfile":true};
            $scope.showinfo = {  "sososhow": false,"sharequer": false, "chileshow": false, "mysharequer": true, "seltxt": false, "selweb": false, "selquer": false , "orgselquer": false,"orgselckt":false  };
        }else if(obj=="seltxt"){ //记事本, "orgselquer": false  
            $scope.discon={"disnewfile":false,"disupfile":false};
            $scope.showinfo = {  "sososhow": false,"sharequer": false, "chileshow": false, "mysharequer": false, "seltxt": true, "selweb": false, "selquer": false, "orgselquer": false,"orgselckt":false   };
        }else if(obj=="selweb"){ //网站收藏
            $scope.discon={"disnewfile":false,"disupfile":false};
            $scope.showinfo = {  "sososhow": false,"sharequer": false, "chileshow": false, "mysharequer": false, "seltxt": false, "selweb": true, "selquer": false , "orgselquer": false,"orgselckt":false};
        }else if(obj=="selque"){ //问答
            $scope.discon={"disnewfile":false,"disupfile":false};
            $scope.showinfo = {  "sososhow": false,"sharequer": false, "chileshow": false, "mysharequer": false, "seltxt": false, "selweb": false, "selquer": true, "orgselquer": false,"orgselckt":false };
        }else if(obj=="tagsel"){ //标签
            $scope.discon={"disnewfile":false,"disupfile":false};
            $scope.showinfo = {  "sososhow": false,"sharequer": false, "chileshow": false, "mysharequer": false, "seltxt": false, "selweb": false, "selquer": false , "orgselquer": false,"orgselckt":false};
        }else if(obj=="sharequer"){ //企业共享文件夹（管理共享给学员的）
            $scope.discon={"disnewfile":true,"disupfile":true};
            $scope.showinfo = {  "sososhow": false,"sharequer": true, "chileshow": false, "mysharequer": false, "seltxt": false, "selweb": false, "selquer": false, "orgselquer": false,"orgselckt":false };
        }else if(obj=="orgsharequer"){ //企业共享文件夹（运营共享给企业的）
            $scope.discon={"disnewfile":true,"disupfile":true};
            $scope.showinfo = {  "sososhow": false,"sharequer": false, "chileshow": false, "mysharequer": false, "seltxt": false, "selweb": false, "selquer": false, "orgselquer": true,"orgselckt":false };
        }else if(obj=="orgsharequer"){ //课件制作
            $scope.discon={"disnewfile":true,"disupfile":true};
            $scope.showinfo = {  "sososhow": false,"sharequer": false, "chileshow": false, "mysharequer": false, "seltxt": false, "selweb": false, "selquer": false, "orgselquer": false,"orgselckt":true };
        }
        //$scope.divoption("sharequer");
    }
    

        //文件共享
    $scope.isfileshare = { divhide: false, data: "", filepath: [] };
    //企业共享文件
        $scope.fileshare=function(kbinfo){    
        if (kbinfo != undefined) {$scope.kbids = []; $scope.kbids.push(kbinfo);}
//        $scope.kbids[0].sel=true; 
//        if ($scope.kbids.length == 0 || $scope.kbids.length > 1) {
//            Msg.info("只能选择一条记录操作！");
//        } else {
//            $scope.selkninfo = $scope.kbids[0];            
            $scope.isfileshare.divhide = true;
            $scope.isfileshare.data = $scope.kbids;//$scope.selkninfo;
//            $scope.isfileattr.filepath = $scope.crumbsknlist;
//            $scope.isfileattr.filestyle = { "left": (document.documentElement.clientWidth - 448) / 2 + "px" };
//        }
        }
        

          //查询运营者共享给企业的文件
    $scope.orgsharedfolder = function () {
        $scope.crumbsknlist=[];
        $scope.divoption("orgsharequer");
        $scope.dbkbids = [];
        $scope.params.searchText = "";
        $scope.sosoText = "";
        $scope.kblist = "";
        $scope.kbids = [];
        $scope.params.pageIndex = 1;
        $scope.params.fileType = "";
        $scope.isloading = true;
        RS.AlreaSharOperatefile($scope.shareparam).then(function (kbdata) {            
            $scope.isloading = false;
            if (kbdata.errorcode == 0) {
                //console.log(kbdata.datas);
                $scope.kblist = kbdata.datas;
                $scope.quesHand($scope.kblist);
            } else {
                console.log(kbdata.errorcode);
            }
        }, function callback() {
            Msg.error("请求数据异常！");
        });
    }
    //视频转码
    $scope.videozhuanma= function(){
        if($scope.kbids.length==0){
            Msg.info("只能选择一条记录操作！");
        }else{
            if($scope.kbids[0].status == "4"){
                Msg.info("提示","正在转换中");
                return;
            }else{
                var videoParams = {
                    userid:sysUserInfo.getuserinfo().user_ID,
                    upid:$scope.kbids[0].upId,
                    orgid:sysUserInfo.getuserinfo().organization_ID
                }
                RS.vedioTranscoding(videoParams).then(function (kbdata) {            
                    $scope.isloading = false;
                    if (kbdata.errorcode == 0) {            
                        // 前端赋值转码        
                        angular.forEach($scope.kblist, function (i, id) {            
                            //遍历判断checkbox是否已选
                            if ($scope.kblist[id].upId == $scope.kbids[0].upId) {
                                $scope.kblist[id].status = 4;
                            }
                        });
                       Msg.success("发送转换成功，请等待！");
                    }else  if (kbdata.errorcode == "62") {// 转换失败
                        Msg.error("非视频文件！");
                    }else {
                        Msg.error("视频转码异常！"+kbdata.errorcode);
                    }
                }, function callback() {
                    Msg.error("请求数据异常！");
                });
            }
        }
    }
    //选择文件转码
     $scope.zhuanhuan = function () {     
        if($scope.kblist.length==0){
            Msg.info("只能选择一条记录操作！");
        }else{
            RS.AgainTranscoding({upid:$scope.kblist[0].upId}).then(function (kbdata) {            
                $scope.isloading = false;
                if (kbdata.errorcode == 0) {
                    $scope.kblist[0].status=0;
                }else  if (kbdata.errorcode == "33") {// 转换失败
                    Msg.error("文件转码失败！")
                }else {
                    Msg.error("文件转码异常！"+kbdata.errorcode);
                }
            }, function callback() {
                Msg.error("请求数据异常！");
            });
        }
    }

    //监控页面尺寸大小
    var w = angular.element($window);
        $scope.getWindowDimensions = function () {
            return { 'h': w[0].innerHeight, 'w': w[0].innerWidth };
        };
        $scope.$watch($scope.getWindowDimensions, function (newValue, oldValue) {
            console.log(newValue.h+"_"+newValue.w);
            if(newValue.w >1200){
                $scope.knowledge_liebiao(0);
            }else{
                $scope.knowledge_liebiao(1);
            }
        }, true);

        w.bind('resize', function () {
            $scope.$apply();
        });
    /*********************************************************************************************************/
    //是否显示新增url
    $scope.showAddUrl=false;
    //打开或关闭
    $scope.openAddUrl=function(){
        $scope.showAddUrl=!$scope.showAddUrl;
    }
    //初始新增参数
    $scope.initAddUrl=function(){
        $scope.auparams={
            fid:"0",
            fpath:"/",
            orgid:sysUserInfo.getuserinfo().organization_ID,
            orgname:sysUserInfo.getuserinfo().organization_Name,
            userid:sysUserInfo.getuserinfo().user_ID,
            username:sysUserInfo.getuserinfo().user_Name,
            filename:"",
            filecover:"",
            fileurlonly:"",
            filepreview:"",
            filesize:0
        };
    }
    //保存的loading
    $scope.aubtnload=false;
    //保存
    $scope.addUrlFun=function(){
        if($scope.auparams.filename.length<=0){
            Msg.warning("请输入文件名称！")
            return;
        }
        if($scope.auparams.fileurlonly.length<=0){
            Msg.warning("请输入文件地址！")
            return;
        }
        $scope.auparams.fid=$scope.params.fid;
        $scope.auparams.filepreview=$scope.auparams.fileurlonly;
        RS.saveUload($scope.auparams).then(function (response) {            
            $scope.isloading = false;
            if (response.errorcode == 0) {
                 Msg.success("保存成功！")
                 $scope.initAddUrl();
                 $scope.openAddUrl();
            }else  if (response.errorcode == "48") {// 转换失败
                Msg.warning("上传文件的格式不支持！");
            }else {
                Msg.error("保存失败！");
            }
        }, function callback() {
            Msg.error("请求数据异常！");
        });
    }
    $scope.initAddUrl();
     /*********************************************************************************************************/
} ]);
